package com.example.myjavaapp.slice;

import com.alibaba.fastjson.JSONObject;
import ohos.agp.components.Text;
import ohos.eventhandler.EventHandler;
import ohos.eventhandler.EventRunner;
import ohos.eventhandler.InnerEvent;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ClockEventHandler extends EventHandler {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, "Demo");

    private Text dateText;

    public ClockEventHandler(EventRunner runner) throws IllegalArgumentException {
        super(runner);
    }
    public ClockEventHandler(EventRunner runner,Text dateText) throws IllegalArgumentException {
        this(runner);
        this.dateText = dateText;
    }

    @Override
    protected  void processEvent(InnerEvent event){
        super.processEvent(event);
        String weather=(String)event.object;
        Map<String,Object> map = JSONObject.parseObject(weather);
        StringBuilder sb = new StringBuilder();
        for(String key:map.keySet()){
            if(!key.equals("cityno")&& !key.equals("weaid")&& !key.equals("weather_icon")){
                String value = map.get(key).toString();
                HiLog.info(LABEL_LOG,"key:"+key+" vlaue:"+value);
                sb.append(value).append(",");
            }
        }
        this.dateText.setText(String.valueOf(sb));
    }
}
